package com.hypo.ribbonserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author: haibo.tang2
 * @Date: 2021/8/13
 * @Description:
 **/
@RestController
public class TestServerController {


    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("getClienPort")
    public String test(){
        List<String> services =
                discoveryClient.getServices();
        System.out.println(services);
        String serviceName="ribbonclient";
        String forObject = restTemplate.getForObject("http://"+serviceName+"/test/getPort", String.class);
        return forObject;

    }
}
